// dockercurloperator.h by wf 2023-10-26
// makefile add -I /usr/include/x86_64-linux-gnu -lcurl
#include <string>
#include <vector>
#include <iostream>
#include "curl/curl.h"
#include "ajson5.h"
#include <fstream>



using std::cout;
using std::vector;
using std::string;
using std::endl;

using namespace ArduinoJson;

struct DockerMount {
	inline DockerMount():readOnly(true){} 
	inline DockerMount(string tar,string src,bool ro):readOnly(ro),targetdir(tar),sourcedir(src){} 

	string targetdir;// container path
	string sourcedir;// host path
	bool readOnly;//default true;
} ;

class DockerCurlOperator {
private:

public:
	// useful
	bool isImageExists(string imageName) ;
	// useful
	bool runCommandsAndRemove(string imageName,
		vector<DockerMount>& mounts, // 
		string containerlogpath,
		vector<string>& commands,
		string& error
		) ;


	bool startContainer(string containerId,string& error) ;
	bool removeContainer(string containerId,bool force,string& error) ;
	bool getContainerLog(string containerId,string& logtext,string& error ) ;
	bool waitContainer(string containerId,string& error) ;
	bool createContainer(
		string imageName,
		vector<DockerMount>& mounts,
		vector<string>& cmds,
		string& retContainerId,
		string& error) ;


	static size_t write_callback(void *contents, size_t length, size_t nmemb,
                                  void *userp) ;
} ;